﻿using BOSTools.DirectoryManifestGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace DirectoryManifestTest
{
    
    
    /// <summary>
    ///This is a test class for DirectoryManifestTaskTest and is intended
    ///to contain all DirectoryManifestTaskTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DirectoryManifestTaskTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Execute
        ///</summary>
        [TestMethod()]
        public void ExecuteTest_Failure()
        {
            DirectoryManifestTask target = new DirectoryManifestTask(); 
            Assert.IsFalse( Directory.Exists( @"z:\xxxyyy" ) );

            target.TargetDirectory = new TaskItem( @"z:\xxxyyy" );
            Assert.AreEqual(@"z:\xxxyyy", target.TargetDirectory.ItemSpec);

            target.OutputFile = new TaskItem(@"c:\output.xml");
            Assert.AreEqual(@"c:\output.xml", target.OutputFile.ItemSpec);
            Assert.IsFalse(target.Execute());
        }

        /// <summary>
        ///A test for Execute
        ///</summary>
        [TestMethod()]
        public void ExecuteTest_Success()
        {
            DirectoryManifestTask target = new DirectoryManifestTask();


            target.TargetDirectory = new TaskItem(TestContext.TestDeploymentDir);
            target.OutputFile = new TaskItem(Path.Combine( TestContext.TestDeploymentDir, "ExecuteTestSuccess.xml" ));
            Assert.IsTrue(target.Execute());
        }
    }

    public class TaskItem : ITaskItem
    {
        public TaskItem(string itemSpec)
        {
            _itemSpec = itemSpec;
        }

        #region ITaskItem Members

        public System.Collections.IDictionary CloneCustomMetadata()
        {
            throw new System.NotImplementedException();
        }

        public void CopyMetadataTo(ITaskItem destinationItem)
        {
            throw new System.NotImplementedException();
        }

        public string GetMetadata(string metadataName)
        {
            throw new System.NotImplementedException();
        }

        private string _itemSpec;

        public string ItemSpec
        {
            get
            {
                return _itemSpec;
            }
            set
            {
                _itemSpec = value;
            }
        }

        public int MetadataCount
        {
            get { return 0; }
        }

        public System.Collections.ICollection MetadataNames
        {
            get { return null; }
        }

        public void RemoveMetadata(string metadataName)
        {
            
        }

        public void SetMetadata(string metadataName, string metadataValue)
        {
            
        }

        #endregion
    }
}
